package szoftlab4sunak;

import java.awt.Canvas;
import java.awt.Graphics;
import java.util.HashMap;
import java.util.Iterator;

public class VMap extends Canvas implements Runnable {
	
	public HashMap<Integer, VCell> vCellStore; 			//Tarolja a cella nezeteket
	public HashMap<Integer, VEnemy> vEnemyStore;		//Tarolja az enemy nezeteket
	public HashMap<Integer, VBattleDevice> vBattleDeviceStore;	//Tarolja a BattleDevice nezeteket
	
	//Konstruktor
	public VMap(){
		this.vCellStore = new HashMap<Integer, VCell>();
		this.vEnemyStore = new HashMap<Integer, VEnemy>();
		this.vBattleDeviceStore = new HashMap<Integer, VBattleDevice>();
	}
	
	//Kirajzolas
	public void paint(Graphics g) {
		
		//Vegigitaral az tarolt Cell nezetken es mindegyiket kirajzolja
		Iterator iter = vCellStore.keySet().iterator();
    	while(iter.hasNext()) {
    	    Integer key = (Integer)iter.next();
    	    VCell ve = vCellStore.get(key);
    	    ve.drawCell(g);
    	}
		
    	//Vegigitaral az tarolt BattleDevice nezetken es mindegyiket kirajzolja
    	iter = vBattleDeviceStore.keySet().iterator();
    	while(iter.hasNext()) {
    	    Integer key = (Integer)iter.next();
    	    VBattleDevice vb = vBattleDeviceStore.get(key);
    	    vb.draw(g);
    	}
    	
    	//Vegigitaral az tarolt Enemy nezetken es mindegyiket kirajzolja
		iter = vEnemyStore.keySet().iterator();					
    	while(iter.hasNext()) {
    	    Integer key = (Integer)iter.next();
    	    VEnemy vc = vEnemyStore.get(key);
    	    if(vc.isDrawable())
    	    	vc.draw(g);
    	}
    			
	}
	
	//Ujra kirajzoltatas
	public void update(Graphics g){
		paint(g);
	}

	@Override
	//Szal kezeles
	public void run() {
		
		while(!java.lang.Thread.currentThread().isInterrupted()){			
			this.repaint();				//Ujra rajzolas
			try
			{
				Thread.currentThread().sleep(100);			//Szal altatasa
			}
			catch (InterruptedException e)
			{
				e.printStackTrace();
			}
		}		
	}
		
}
